<?php

namespace App\Service\Cruise\Shop;

use App\Enums\BaseErrorCode;
use App\Enums\Cruise\CruiseEnum;
use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Exceptions\Custom\ResponseHttpException;
use App\Library\Rms\RmsShopApi;
use App\Models\BaseModel;
use App\Models\Cruise\CruiseCheckAgainstModel;
use App\Models\Cruise\CruiseCheckDetailModel;
use App\Models\Cruise\CruiseOrderModel;
use App\Models\Cruise\CruiseShopAccountModel;
use App\Models\Cruise\CruiseTemplateModel;
use App\Models\OpenShop\Common\OpenShopOrderManagerModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopAddressModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopMainProcessModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationModel;
use App\Models\OpenShop\StartBusiness\OpenShopStartBusinessModel;
use App\Models\Shop\ShopModel;
use App\Remote\Orm\OrmNewOrderRemote;
use App\Remote\Rms\RmsShopRemote;
use App\Service\Cruise\Archive\ArchiveService;
use App\Service\Cruise\Check\CruiseOrderService;
use App\Service\OpenShop\Feishu\OrganizationManageService;
use App\Service\OpenShop\Feishu\OrganizationManageUserService;
use App\Service\OpenShop\User\RmsUserService;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;

class CruiseShopService
{

    /**
     * 获取门店列表
     * @param $orderBy
     * @param $pageNum
     * @param $pageSize
     * @param $name
     * @param $shopCode
     * @param $cityCode
     * @param $level
     * @param $status
     * @param $orderPermission
     * @param $orderRatioMin
     * @param $orderRatioMax
     * @param $shopGrade
     * @param $arriveDays
     * @return array
     * @throws GuzzleException
     */
    public static function list(
        $orderBy,
        $pageNum,
        $pageSize,
        $name,
        $shopCode,
        $cityCode,
        $level,
        $status,
        $orderPermission,
        $orderRatioMin,
        $orderRatioMax,
        $shopGrade,
        $arriveDays
    ): array
    {
        // $shopIdBasicSql = OpenShopMainProcessModel::query()
        //     ->when($arriveDays, function ($query) use ($arriveDays) {
        //         $child2 = CruiseOrderModel::query()
        //             ->where(function ($query) use ($arriveDays) {
        //                 $child1 = CruiseCheckDetailModel::query()
        //                     ->where('templateType', CruiseTemplateModel::TYPE_3)
        //                     ->where('submitTime', '>', Carbon::now()->subDays($arriveDays)->timestamp)
        //                     ->select('orderId');
        //                 $query->whereRaw("cruise_order.id in (" . BaseModel::toSqlWithParam($child1) . ')');
        //             })->select('shopId');
        //         $query->whereRaw("shopId not in (" . BaseModel::toSqlWithParam($child2) . ")");
        //     })
        //     ->where(function ($query) {
        //         $child = OpenShopSignOrderModel::query()
        //             ->whereIn('status', [SignOrderEnum::ORDER_STATUS_OK, SignOrderEnum::ORDER_STATUS_COMPLETE])
        //             ->select('orderNo');
        //         $query->whereRaw("orderNo in (" . BaseModel::toSqlWithParam($child) . ')');
        //     })
        //     ->when(mb_strlen($name), function ($query) use ($name) {
        //         $rmsShopListResult = ShopModel::query()->where('name', 'like', "%{$name}%")->pluck('id')->toArray();
        //         $shopIds = collect($rmsShopListResult)->pluck('id')->implode(',');
        //         if(!empty($shopIds)){
        //             $shopIdSqlRow = "shopId in({$shopIds}) ";
        //         }else{
        //             $shopIdSqlRow = "shopId = 0 ";
        //         }
        //
        //         $query->where(function ($qq) use ($shopIdSqlRow, $name){
        //             $qq->whereRaw("orderNo in (select `orderNo` from `open_shop_user_identity_card` where `name` like '%{$name}%')")
        //                 ->orWhereRaw($shopIdSqlRow);
        //         });
        //     })
        //     ->when(mb_strlen($shopCode), function ($query) use ($shopCode) {
        //         $child = OpenShopSignOrderModel::query()
        //             ->where('shopCode', $shopCode)
        //             ->select('orderNo');
        //         $query->whereRaw("orderNo in (" . BaseModel::toSqlWithParam($child) . ')');
        //     })
        //     ->when($cityCode, function ($query) use ($cityCode, $level) {
        //         switch ($level) {
        //             case 1:
        //                 $area = 'provinceCode';
        //                 break;
        //             case 2:
        //                 $area = 'cityCode';
        //                 break;
        //             case 3:
        //                 $area = 'areaCode';
        //                 break;
        //             default:
        //                 $area = 'cityCode';
        //         }
        //         $child = OpenShopAddressModel::query()
        //             ->where($area, $cityCode)
        //             ->select('orderNo');
        //         $query->whereRaw("orderNo in (" . BaseModel::toSqlWithParam($child) . ')');
        //     })
        //     ->when(!$orderPermission['isAll'], function ($query) use ($orderPermission) {
        //         $query->whereRaw($orderPermission['rawSql']);
        //     })
        //     ->where(function ($query) use ($status) {
        //         switch ($status) {
        //             case CruiseEnum::OPEN_BUSINESS:
        //                 $child = OpenShopStartBusinessModel::query()
        //                     ->where('startBusinessTime', '>', 0)
        //                     ->where('startBusinessTime', '<', time())
        //                     ->select('orderNo');
        //                 break;
        //             case CruiseEnum::NOT_OPEN_BUSINESS:
        //                 $child = OpenShopStartBusinessModel::query()
        //                     ->where(function ($q) {
        //                         $q->where('startBusinessTime', 0)
        //                             ->orWhere('startBusinessTime', '>', time());
        //                     })
        //                     ->select('orderNo');
        //                 break;
        //             default:
        //                 $child = false;
        //         }
        //         if ($child !== false) {
        //             $query->whereRaw("orderNo in (" . BaseModel::toSqlWithParam($child) . ')');
        //         }
        //     })
        //     ->select('shopId');


        $paginator = CruiseShopAccountModel::query()
            ->when(!$orderPermission['isAll'], function ($query) use ($orderPermission) {
                $query->whereRaw($orderPermission['rawSql']);
            })
            ->when($cityCode, function ($query) use ($cityCode, $level) {
                switch ($level) {
                    case 1:
                        $area = 'provinceCode';
                        break;
                    case 2:
                        $area = 'cityCode';
                        break;
                    case 3:
                        $area = 'districtCode';
                        break;
                    default:
                        $area = 'cityCode';
                }
                $query->where($area, $cityCode);
            })
            ->when($status != -1, function ($query) use ($status) {
                $query->where('businessStatus', $status);
            })
            ->when(mb_strlen($name), function ($query) use ($name) {
                $query->where('franchiseeName', 'like', "%{$name}%")->orWhere('shopName', 'like', "%{$name}%");
            })
            ->when(mb_strlen($shopCode), function ($query) use ($shopCode) {
                $query->where('shopCode', $shopCode);
            })
            ->when($arriveDays, function ($query) use ($arriveDays) {
                $query->where('daysWithoutCruise', '<', $arriveDays);
            })
            ->where('shopId', '>', 0)
            ->when($shopGrade, function ($query) use ($shopGrade) {
                $query->where('shopGrade', $shopGrade);
            })
            ->when($orderRatioMax, function ($query) use ($orderRatioMin, $orderRatioMax) {
                $query->whereRaw("(`turnover` > 0 and orderRatioNumber between {$orderRatioMin} and {$orderRatioMax})");
            })
            //->whereRaw("shopId in (" . BaseModel::toSqlWithParam($shopIdBasicSql) . ")")
            ->when($orderBy, function ($query) use ($orderBy) {
                switch ($orderBy) {
                    case 1:
                        $query->orderByDesc('turnover');
                        break;
                    case 2:
                        $query->orderBy('turnover');
                        break;
                    case 3:
                        $query->orderByDesc('orderAmount');
                        break;
                    case 4:
                        $query->orderBy('orderAmount');
                        break;
                    default:
                        $query->orderByDesc('turnover');
                }
            })
            ->with(['cruiseOrderRel.checkTaskDetailRel'])
            ->paginate($pageSize, ['*'], 'pageNum', $pageNum);

        $shopIds       = $paginator->pluck('shopId')->toArray();
        $shopBusiness  = array_column((new RmsShopApi())->shopBusiness($shopIds, ['shopId', 'date'])['data'] ?? [], 'date', 'shopId');

        //获得门店上次巡检日期
        $patrolData = CruiseOrderService::lastCruiseTime(0, 0, $shopIds);
        $patrolList = count($patrolData) ? array_column($patrolData, 'submitTime', 'shopId') : [];

        // 获取门店信息
        $shopList = [];
        ShopModel::query()
            ->whereIn('id', $shopIds)
            ->select(['id', 'shopCode', 'name'])
            ->get()
            ->map(function ($shop) use (&$shopList){
                $shopList[$shop->id] = [
                    'id'       => $shop->id,
                    'shopCode' => $shop->shopCode,
                    'name'     => $shop->name,
                ];
            });

        $list       = $paginator->map(function ($item) use ($shopList, $patrolList, $shopBusiness) {
            $patrol = $patrolList[$item->shopId] ?? '';
            if ($patrol) {
                $patrolText = formatDateYmd($patrol) . ' (' . ((int)((time() - $patrol) / 86400) ? (int)((time() - $patrol) / 86400) . '天前)' : '今天)');
            } else {
                $patrolText = '-';
            }
            //查询 门店档案-营业执照和许可证 状态
            $shopArchiveDetail = ArchiveService::shopArchiveDetail($shopList[$item->shopId]['id'] ?? 0, 1);
            return [
                'id'                        => $item->id,
                'shopId'                    => $shopList[$item->shopId]['id'] ?? 0,
                'shopInfo'                  => 'KF' . sprintf("%04d", ($shopList[$item->shopId]['shopCode'] ?? '0000')) . ' ' . ($shopList[$item->shopId]['name'] ?? '-'),
                'supervise'                 => $item->managerName,
                'patrol'                    => $patrolText,
                'shopGrade'                 => OpenShopSiteLocationModel::HOUSE_GRADE_SIFT_MAPPING[$item->shopGrade] ?? '-',
                'dossier'                   => $item->orderRatio,
                'errorInfo'                 => '',
                'username'                  => $item->franchiseeName,
                'tip'                       => (strtotime(formatDateYmd(time())) - 259200) > (($shopBusiness[$item->shopId] ?? 0) ? strtotime($shopBusiness[$item->shopId]) : 0), //提示是否三天内没有营业额
                'shopArea'                  => $item->area,
                'statusText'                => CruiseShopAccountModel::BUSINESS_STATUS_MAPPING[$item->businessStatus] ?? '-',
                'status'                    => $item->businessStatus,
                'time'                      => $item->preOpenTime ? formatDateYmd($item->preOpenTime) : '-',
                'businessLicenseStatus'     => $shopArchiveDetail['businessLicenseStatus'] ?? ArchiveService::LICENSE_STATUS_NOT_FOUND,
                'foodBusinessLicenseStatus' => $shopArchiveDetail['foodBusinessLicenseStatus'] ?? ArchiveService::LICENSE_STATUS_NOT_FOUND,
            ];
        });
        return [
            'list'     => $list,
            'count'    => $paginator->total(),
            'pageNum'  => $pageNum,
            'pageSize' => $pageSize,
        ];
    }

    /**
     * 获取门店详情
     * @param $shopId
     * @param $type
     * @return array
     * @throws GuzzleException
     */
    public static function detail($shopId, $type = CruiseOrderModel::TYPE_NEW_SHOP_HELP)
    {
        $cruiseShopAccountModel = CruiseShopAccountModel::query()
            ->where('shopId', $shopId)
            ->with(['siteLocationRel', 'orderManagerRel', 'startBusinessRel', 'cruiseOrderRel.checkTaskDetailRel', 'signOrderRel', 'franchiseeArchivesRel', 'userWorkExperienceRel'])
            ->first();

        if (null == $cruiseShopAccountModel) {
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, "查询不到该门店信息");
        }

        $shopCount = 0;
        if ($cruiseShopAccountModel->signOrderRel->count()) {
            OpenShopSignOrderModel::query()
                ->whereIn('status', [SignOrderEnum::ORDER_STATUS_OK, SignOrderEnum::ORDER_STATUS_COMPLETE])
                ->where('merchantUserId', $cruiseShopAccountModel->signOrderRel[0]->merchantUserId)
                ->with(['progressRel'])
                ->get()
                ->each(function (OpenShopSignOrderModel $openShopSignOrderQuery) use (&$shopIds, &$shopCount) {
                    if (null != $openShopSignOrderQuery->progressRel) {
                        $shopIds[] = $openShopSignOrderQuery->progressRel->shopId;
                        if ($openShopSignOrderQuery->progressRel->shopId > 0) {
                            ++$shopCount;
                        }
                    }
                });
        }

        //省总Uid
        $provinceManagerId = 0;
        if ($cruiseShopAccountModel->siteLocationRel->count()) {
            $provinceManagerId = OrganizationManageService::getProvinceInfoByProvinceCode($cruiseShopAccountModel->siteLocationRel[0]->provinceCode)['operationUid'] ?? 0;
        }

        //督导
        $superviseId = 0;
        if ($cruiseShopAccountModel->orderManagerRel->count()) {
            foreach ($cruiseShopAccountModel->orderManagerRel as $value) {
                if ($value->type == OpenShopOrderManagerModel::MANAGER_TYPE_5) {
                    $superviseId = $value->managerUid;
                    break;
                }
            }
        }
        if ($type == CruiseOrderModel::TYPE_CHECK) {
            //获取稽核督导
            $checkManager = OrganizationManageUserService::getCruiseCheckManager($shopId);
            $superviseId  = $checkManager['userId'] ?? $superviseId;
        }
        $userInfo = RmsUserService::getRmsUserInfoByUserIds([$superviseId, $provinceManagerId])['data'] ?? [];
        $shopInfo = (new RmsShopApi())->getShopByIds([$shopId], ['id', 'shopCode', 'name', 'type', 'lng', 'lat', 'addressPrefix', 'address'])['data']['shopList'] ?? [];
        $userList = array_column($userInfo, null, 'id');
        $shopList = array_column($shopInfo, null, 'id');

        $startTime = '-';
        if ($cruiseShopAccountModel->startBusinessRel->count()) {
            $startTime = $cruiseShopAccountModel->startBusinessRel[0]->startBusinessTime ? formatDateYmd($cruiseShopAccountModel->startBusinessRel[0]->startBusinessTime) : '-';
        }

        $checkReport = [];
        if (count($cruiseShopAccountModel->cruiseOrderRel)) {
            foreach ($cruiseShopAccountModel->cruiseOrderRel as $cruiseOrder) {
                if (null == $cruiseOrder->checkTaskDetailRel || !in_array($cruiseOrder->checkTaskDetailRel->reportResult, [CruiseCheckDetailModel::REPORT_RESULT_QUALIFIED, CruiseCheckDetailModel::REPORT_RESULT_UNQUALIFIED])) {
                    continue;
                }
                $checkReport[] = [
                    'shopInfo'   => 'KF' . sprintf("%04d", ($shopList[$cruiseShopAccountModel->shopId]['shopCode'] ?? '0000')) . ' ' . ($shopList[$cruiseShopAccountModel->shopId]['name'] ?? '-'),
                    'code'       => $cruiseOrder->checkTaskDetailRel->code,
                    'createdAt'  => $cruiseOrder->checkTaskDetailRel->createdAt->format('Y-m-d H:i:s'),
                    'total'      => $cruiseOrder->checkTaskDetailRel->totalNum,
                    'errorCount' => $cruiseOrder->checkTaskDetailRel->failNum,
                    'result'     => CruiseCheckDetailModel::REPORT_RESULT_MAPPING[$cruiseOrder->checkTaskDetailRel->reportResult],
                    'id'         => $cruiseOrder->checkTaskDetailRel->id
                ];
            }
        }

        if ($cruiseShopAccountModel->cruiseOrderRel) {
            $processInfo = [];
        } else {
            $processInfo = [
                'type'          => CruiseOrderModel::CRUISE_TYPE_MAPPING[$cruiseShopAccountModel->cruiseOrderRel->type] ?? '-',
                'statusText'    => CruiseOrderModel::CRUISE_STATUS_MAPPING[$cruiseShopAccountModel->cruiseOrderRel->status] ?? '-',
                'cruiseOrderId' => $cruiseShopAccountModel->cruiseOrderRel->id,
                'isLook'        => $cruiseShopAccountModel->cruiseOrderRel->status != CruiseOrderModel::STATUS_NOT_SUBMIT
            ];
        }

        // 获取该门店员工信息
        $staffData = (new RmsShopApi())->getShopStaffListByShopId($shopId)['data']['list'] ?? [];

        return [
            'baseInfo'    => [
                'startBusinessStatus'  => CruiseShopAccountModel::BUSINESS_STATUS_MAPPING[$cruiseShopAccountModel->businessStatus] ?? '-',
                'status'               => $cruiseShopAccountModel->businessStatus,
                'time'                 => $startTime,
                'shopTypeText'         => in_array(($shopList[$cruiseShopAccountModel->shopId]['type'] ?? 0), [RmsShopApi::SHOP_TYPE_LEAGUE, RmsShopApi::SHOP_TYPE_DIRECT]) ? RmsShopApi::SHOP_TYPE_MAPPING[$shopList[$cruiseShopAccountModel->shopId]['type']] : '-',
                'shopType'             => $shopList[$cruiseShopAccountModel->shopId]['type'] ?? 0,
                'shopName'             => $shopList[$cruiseShopAccountModel->shopId]['name'] ?? '-',
                'shopInfo'             => 'KF' . sprintf("%04d", ($shopList[$cruiseShopAccountModel->shopId]['shopCode'] ?? '0000')) . ' ' . ($shopList[$cruiseShopAccountModel->shopId]['name'] ?? '-'),
                'userName'             => $cruiseShopAccountModel->franchiseeName,
                'mobile'               => '',
                'shopCount'            => $shopCount . '家店',
                'supervise'            => $userList[$superviseId]['username'] ?? '-',  // 督导
                'supervisePosition'    => '稽核督导',                                  //todo 督导职位
                'supervisePhone'       => $userList[$superviseId]['mobile'] ?? '',
                'provinceManager'      => $userList[$provinceManagerId]['username'] ?? '-',
                'provinceManagerPhone' => $userList[$provinceManagerId]['mobile'] ?? ''
            ],
            'mission'     => $processInfo,
            'address'     => [
                'area'   => $shopList[$cruiseShopAccountModel->shopId]['addressPrefix'] ?? '-',
                'detail' => $shopList[$cruiseShopAccountModel->shopId]['address'] ?? '-',
                'lng'    => $shopList[$cruiseShopAccountModel->shopId]['lng'] ?? 0,
                'lat'    => $shopList[$cruiseShopAccountModel->shopId]['lat'] ?? 0,
            ],
            'shopGarde'   => OpenShopSiteLocationModel::HOUSE_GRADE_SIFT_MAPPING[$cruiseShopAccountModel->shopGrade] ?? '-',
            'errorInfo'   => '',
            'orderRatio'  => $cruiseShopAccountModel->orderRatio,
            'shopId'      => $cruiseShopAccountModel->shopId,
            'dossier'     => '35%',  //暂时不做
            'checkReport' => $checkReport,
            'staffList'   => collect($staffData)->where('inShop', 0)->values()->toArray()
        ];
    }

    public static function orderTarget($month, $shopId)
    {
        $orm = OrmNewOrderRemote::getOrderTargetByMonth($month, $shopId);
        if ($orm['code'] == 0) {
            $list = $orm['data'];
        } else {
            throw new ResponseHttpException(BaseErrorCode::$ERROR_OCCURRED, null, $orm['msg'] ?? '获取订货指标失败');
        }
        // 0 订货金额  1 订货数量  2 订单量  3  订货比
        $turnover  = (new RmsShopApi())->originalPrice($shopId, strtotime($month), (strtotime('+1month', strtotime($month)) - 1))['data']['originalPrice'] ?? 0;
        $turnover1 = (new RmsShopApi())->originalPrice($shopId, strtotime('-1month', strtotime($month)), (strtotime($month)) - 1)['data']['originalPrice'] ?? 0;
        //订货比  订货额/营业额
        //$month 的订货比
        $orderRate = ($list[0]['num'] * 100) / ($turnover ?: 1);
        //$month -1 month 的订货比
        $orderRate1            = (($list[0]['num'] - $list[0]['changeNum'] * 100)) / ($turnover1 ?: 1);
        $list[3]['num']        = $orderRate;
        $list[3]['changeNum']  = $orderRate - $orderRate1;
        $list[3]['changeRate'] = $orderRate1 ? (($orderRate - $orderRate1) / $orderRate1 * 100) : 100;
        Log::info('CRUISE-ORDER-TARGET:shopId:' . $shopId . '===' . $month . '  <1>营业额:' . $turnover . '  <2>订货额:' . $list[0]['num'] * 100 . 'ps:订货比=订货额/营业额');
        return collect($list)->map(function ($item) {
            $item['num']        = $item['name'] == '订货比' ? (round(($item['num'] * 100), 2) . '%') : round($item['num'], 2);
            $item['changeNum']  = $item['name'] == '订货比' ? (round(($item['changeNum'] * 100), 2) . '%') : round($item['changeNum'], 2);
            $item['changeRate'] = round($item['changeRate'], 2);
            return $item;
        })->toArray();
    }

    public static function getOpenBusinessCount($orderPermission, $cityCode)
    {

        $total           = 0;
        $openBusiness    = 0;
        $notOpenBusiness = 0;

        OpenShopSignOrderModel::query()
            ->with(['startBusinessRel'])
            ->whereIn('status', [SignOrderEnum::ORDER_STATUS_OK, SignOrderEnum::ORDER_STATUS_COMPLETE])
            ->when($cityCode, function ($query) use ($cityCode) {
                $child = OpenShopAddressModel::query()
                    ->where('cityCode', $cityCode)
                    ->select('orderNo');
                $query->whereRaw("orderNo in (" . BaseModel::toSqlWithParam($child) . ')');
            })
            ->when(!$orderPermission['isAll'], function ($query) use ($orderPermission) {
                $query->whereRaw($orderPermission['rawSql']);
            })
            ->get()
            ->each(function ($item) use (&$total, &$openBusiness, &$notOpenBusiness) {
                if (null != $item->startBusinessRel) {
                    if ($item->startBusinessRel->startBusinessTime > 0 && $item->startBusinessRel->startBusinessTime < time()) {
                        ++$openBusiness;
                    } else {
                        ++$notOpenBusiness;
                    }
                } else {
                    ++$notOpenBusiness;
                }
                ++$total;
            });

        return [
            'list' => [
                [
                    'label'   => CruiseEnum::BUSINESS_STATUS_MAPPING[CruiseEnum::TOTAL_BUSINESS],
                    'value'   => CruiseEnum::TOTAL_BUSINESS,
                    'shopNum' => $total,
                    'checked' => false,
                ], [
                    'label'   => CruiseEnum::BUSINESS_STATUS_MAPPING[CruiseEnum::OPEN_BUSINESS],
                    'value'   => CruiseEnum::OPEN_BUSINESS,
                    'shopNum' => $openBusiness,
                    'checked' => false,
                ], [
                    'label'   => CruiseEnum::BUSINESS_STATUS_MAPPING[CruiseEnum::NOT_OPEN_BUSINESS],
                    'value'   => CruiseEnum::NOT_OPEN_BUSINESS,
                    'shopNum' => $notOpenBusiness,
                    'checked' => false,
                ]
            ]
        ];
    }


    /**
     * 修改门店收银状态
     * @param int $shopId
     * @param int $status
     * @return void
     * @throws GuzzleException
     */
    public static function updateCashRegisterStatusByShopId(int $shopId, int $status = RmsShopRemote::SHOP_CASH_REGISTER_STATUS_CHECK_OFF)
    {
        //判断稽核是否触发违约支付
        $count = CruiseCheckAgainstModel::query()
            ->where('shopId', $shopId)
            ->where('status', CruiseCheckAgainstModel::STATUS_WAIT)
            ->where('level', CruiseCheckAgainstModel::LEVEL_PUNISH)
            ->where('endTime', '<', isProd() ? Carbon::now()->subDays(8)->timestamp : time())   //8天后关闭收银
            ->count();

        Log::info("updateCashRegisterStatusByShopId:{$count} shopId:{$shopId} ");
        if ($count) {
            RmsShopRemote::updateShopFieldById($shopId, ['cashRegisterStatus' => $status, 'dyCouponVerifySwitch' => 0]);
        }
    }

}

